'use strict';
exports = module.exports = function ( $scope, $alert, $uibModal, $timeout, $ajax ) {
    // 显示调试信息
    $scope.frm = {
        f01: '',
        f02: '',
        f03: '',
        f04: 0, // 开关
        f05: '',
        f06: 0, // 级联开关
        f07: 0, // switch
        f08: '', // 日期
        f09: '', // 增删表格单元
        f10: ['111', '222'], // 增删表格
        f11: '', // 组合增删表格单元
        f12: '', // 组合增删表格单元
        f13: '', // 组合增删表格单元
        f14: [], // 组合增删表格

        f15: '', f15a: '',
        f16: '', f16a: '',
        f17: '', f17a: '',
        f18: '', f18a: '',
        f19: '',
        f20: '',
        f21: '',
        f22: '',
        f23: '', //文件上传

        showDebugger: false
    };
    $scope.frm2 = {
        f02list: select2Config([], 1),
        f07change: function(){
            if( $scope.From.$invalid ) {
                $scope.From.submitted = true;
                console.log($scope.From.$error)
                $alert.error('请先填写表单,然后看情况')
                return
            }
            $scope.frm.f07 = Math.abs($scope.frm.f07-1);
        },
        f10add: function(submitBtn){
            if(!$scope.frm.f09){return false}
            var xx = angular.copy($scope.frm.f10);
            xx.push($scope.frm.f09);
            $scope.frm.f09 = ''
            $scope.frm.f10 = xx
            submitBtn.enable();
        },
        f10delete: function(index){
            var xx = angular.copy($scope.frm.f10);
            xx.splice(index, 1);
            $scope.frm.f10 = xx
        },
        f11list: select2Config([], 0),
        f14Btn: false,
        f14add: function(submitBtn){
            var isinvalid = $scope.frm2.f14Btn = (!$scope.frm.f11||!$scope.frm.f12||!$scope.frm.f13)
            if( isinvalid ) {
                submitBtn.enable();
                return
            }
            $scope.frm.f14.push({
                k: $scope.frm.f11,
                f: $scope.frm.f12,
                c: $scope.frm.f13
            });
            $scope.frm.f11 = ''
            $scope.frm.f12 = ''
            $scope.frm.f13 = ''
            submitBtn.enable();
        },
        f14delete: function(index){
            $scope.frm.f14.splice(index, 1);
        },
        f23: null, //文件对象
        f23upload: function(){
            //根据自己需要的类型进行判断
            var file = $scope.frm2.f23;
            if( file.type != 'image/png' ){
                $alert.error('请上传png格式图片')
                return;
            }
            _upload();
            function _upload(){
                var data = new FormData(); //存储文件格式流数据
                data.append('addFile', file);
                var option = {
                    real: true,
                    url: '/ng1x/fileUpload',
                    method: 'POST',
                    data: data, //仅仅存放的是文件流数据
                    headers: { 'Content-Type': undefined }, //angularjs设置文件上传的content-type修改方式
                    transformRequest: angular.identity
                };
                $ajax.sent(option).then((res) => { /*图片上传完成返回临时路径该给谁给谁*/
                    console.log(res);
                    $timeout(function(){
                        $scope.frm.f23 = res.data.path;
                    },0)
                }).catch((res) => {
                    console.error(res);
                });
            }
        }
    };
    $timeout(function(){
        var data = [
            {'id':1496,'name':'x109698142(向延杰)'},{'id':1568,'name':'sm1111(郸仁辉)'},
            {'id':10990,'name':'donameg891109(边国栋)'},{'id':19633,'name':'wwqzx9961(黄海锋)'}
        ];
        $scope.frm2.f02list = select2Config(data, 1);
        $scope.frm2.f11list = select2Config(data);
    } ,2e3)
    $scope.submitFun = function($submitBtn){
        $scope.From.submitted = true;
        if( $scope.From.$invalid ) {
            $submitBtn.enable();
            $alert.error('请检查提交的信息')
            return
        }
        $timeout(function(){
            console.log($scope.frm);
            $submitBtn.enable();
        },3e3)
        return;
    };
    $scope.Rule = {
        isNumFixed2: function(value) {
            return value === parseFloat(value).toFixed(2).toString()
        },
        isNum: function(value) {
            return value === parseInt(value).toString()
            || value === parseFloat(value).toFixed(1).toString()
            || value === parseFloat(value).toFixed(2).toString()
        }
    };
}
